<?php

namespace app\admin\controller;

use app\admin\common\Base;
use think\Db;
use think\Request;

class Admins extends Base
{
    /**
     * 显示管理员列表
     */
    public function index()
    {
        $data = Db::table('admins')->select();
        $this->assign('data',$data);
        return $this->fetch('admin_list');
    }
    /**
     * 修改密码
     */
    public function edit()
    {
        $id = (int)input('get.id');
        $data = Db::table('admins')->where(array('id'=>$id))->find();
        $this->assign('data',$data);
        return $this->fetch('admin_edit');
    }

    /**
     * 保存管理员
     *
     */
    public function update()
    {
        $id = (int)input('post.id');
        $data['username'] = trim(input('post.username'));
        $password = trim(input('post.password'));
        if($password){
            //密码处理
            $data['password'] = md5($data['username'].$password);
        }
        $res=Db::table('admins')->where(array('id'=>$id))->update($data);
        if($res){
            exit(json_encode(array('code'=>0,'msg'=>'保存成功')));
        }
    }
}
